	#include("/common/include/include.html")
<div class="admin-main">
	<div class="site-block-full navi-left" style="top: 0px;">
		<fieldset><legend>菜单导航</legend>
			<ul id="menuTree"></ul>
		</fieldset>
	</div>
	<div class="site-block-full main-right" style="top: 0px;">
		<fieldset><legend>数据列表</legend>
			<table class="site-table table-hover">
				  <thead>
					    <tr><th style="width: 12px;padding-left: 15px;"></th><th>功能名称</th><th>所属模块</th><th>地址</th></tr> 
				  </thead>
				  <tbody id = "tableBody"></tbody>
			</table>           
	     	<div class="admin-table-page"><div id="pages" class = "pages"></div></div>
		</fieldset>
	</div>
	<div class = "selecterBtnDiv">
		<a href="javascript:;" class="layui-btn layui-btn-small" onclick="selectOneOperate()">
			<i class="layui-icon">&#xe608;</i> 确定
		</a>
	</div>
</div>
		<!--模板-->
		<script type="text/html" id="conTemp">
				{{# layui.each(d.data, function(index, item){ }}
					<tr>
						<td><input type="checkbox" class="icheckbox_flat-green" value="{{ item.id?item.id:"" }}"></td>
						<td>{{ item.name?item.name:"" }}</td>
						<td>{{ item.mname?item.mname:"" }}</td>
						<td style="text-align: left;">{{ item.url?item.url:"" }}</td>
					</tr>
				{{# }); }}
		</script>
<script>
 	var mid = '#(mid)';
	layui.config({
		  base: ctx+'/common/js/'
	}).use(['tree','ajax','paging'], function(){
			 ajax = layui.ajax;
			 tree = layui.tree;
			 paging = layui.paging();
			 refresh();
	});
	function refresh(){
		initTree();
		getPageData("");
	}
	//初始化左侧菜单树
	function initTree(){
		$("#menuTree").html("")
		var d = ajax.ajaxFunc(ctx+"/admin/module/getAllMenuTree",null,"json",null);
		layui.tree({
		    elem: '#menuTree' //传入元素选择器
		    ,nodes: d.data
		    ,click: function(node){
		    	getPageData(node.id);
		    }  
		});
	}
	//获取分页数据
	function getPageData(mid){
		paging.init({
			url: ctx+"/admin/operate/listData",  //地址
			elem: '#tableBody',
			tempElem: '#conTemp',  //模块容器
			pageConfig: {        //分页参数配置
				elem: '#pages',  //分页容器
				pageSize: 10,     //分页大小
				mid:mid
			}
		});
	}
	//选择一个功能
	function selectOneOperate(){
		var p = $(".icheckbox_flat-green.checked");
		var length = p.length;
		if(!length&&length<=0){
			parent.layer.alert("请选择要绑定的功能!");
			return;
		}
		if(length>1){
			parent.layer.alert("请选择一行!");
			return;
		}
		var data = {};
		data.mid = mid;
		data.oid = p.find("input").val();
		var r = ajax.ajaxFunc(ctx+"/admin/menu/addOperateToMenu",data,"json",null);
		if(r.success){
			parent.layer.closeAll();
			parent.layer.alert(r.message);
		}
	}
</script>